#ifndef CEVENTSYSTEM_H_
#define CEVENTSYSTEM_H_
#include <queue>
#include <map>
#include <string>
using std::queue;
using std::multimap;
using std::pair;
using std::string;

struct tEvent
{
	string	m_szEventID;
	void   *m_pSender;
	void   *m_pArgs;

	tEvent() { m_pSender = m_pArgs = 0; }

	void SetParams(string szID, void *pSender, void *pArgs)
	{
		m_szEventID = szID;
		m_pSender = pSender;
		m_pArgs = pArgs;
	}
};

class IListener
{
public:
	virtual void HandleEvent(string szEventID, void *pSender, void *pArgs) = 0;
};

class CDispatcher
{
private:
	multimap<string, IListener *>	m_mRegistry;
	queue<tEvent>					m_qEvents;

	void DispatchEvent(tEvent *Event);

	CDispatcher() { }
	CDispatcher(CDispatcher &) { }
	CDispatcher &operator=(CDispatcher &) { }
public:
	~CDispatcher() { }

	static CDispatcher *GetInstance();

	void RegisterClient(string szID, IListener *pClient);
	void UnregisterClient(string szID, IListener *pClient);

	void SendEvent(string szID, void *pSender, void *pArgs);
	void ProcessEvents();
	void ClearEvents();
};

#endif